<template>
  <div>
    <nav-bar class="nav-bar">
      <div slot="left" class="back" @click="back">
        <img src="../../../assets/img/common/back.svg" alt="" />
      </div>
      <div slot="center" class="titles">
        <div
          v-for="(item, index) in titles"
          :key="index"
          :class="{ active: index == currentIndex }"
          @click="titleClick(index)"
        >
          {{ item }}
        </div>
      </div>
    </nav-bar>
  </div>
</template>

<script>
// 导航组件
import NavBar from "components/common/navbar/NavBar";
export default {
  name: "DetailNavBar",
  components: {
    NavBar
  },
  data() {
    return {
      titles: ["商品", "参数", "评论", "推荐"],
      currentIndex: 0
    };
  },
  methods: {
    titleClick(index) {
      this.currentIndex = index;
      this.$emit('titleClick', index);
    },
    back() {
      this.$router.back();
    }
  }
};
</script>

<style lang="less" scoped>
.titles {
  text-align: center;
  display: flex;
  font-size: 0.9rem;
  > div {
    flex: 1;
    &.active {
      color: var(--color-high-text);
      font-weight: 700;
    }
  }
}
.back {
  padding-top: 0.3rem;
}
.nav-bar {
  background: #fff;
}
</style>
